package com.fzy.common.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 请取每一行数据，然后格式化字符串数据为xx,xx,xx
 *
 * @author 冯赵杨
 * @date 2018年3月7日
 */
public class TextFileStringFormat {

    public static void main(String[] args) {
        String filePath = "D:/test.txt";
        String str = readTextFile(filePath);

        System.out.println(str);
    }

    public static String readTextFile(String filePath) {
        StringBuilder sb = new StringBuilder();
        try {
            FileInputStream fis = new FileInputStream(new File(filePath));
            InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line).append(",");
            }
            br.close();
            isr.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return sb.toString();
    }
}
